<template>
	<view class="pack">
		<commonList :isDataEmpty="isDataEmpty" :status="status">
			<template #list>
				<view class="">
					<view class="list">
						<view class="item flex align-center" v-for="(item, index) in tableData" :key="index">
							<view class="item-left">
								<view class="name">{{ item.name }}</view>
								<view class="exit-time">{{ item.create_at }}</view>
							</view>
							<view class="btn">
								<button @click="handReceive(item)">到店领取</button>
							</view>
						</view>
					</view>
				</view>
			</template>
		</commonList>
		<receive-dia ref="receiva" />
	</view>
</template>

<script>
	import {
		doBoxList
	} from "@/api/home.js"
	import commonList from '@/components/commonList/list.vue'
	import receiveDia from './components/receiveDia.vue'
	export default {
		components: {
			commonList,
			receiveDia
		},
		data() {
			return {
				tableData: [],
				queryForm: {
					pageNo: 1,
					pageSize: 10
				},
				status: 'loading',
			}
		},
		computed: {
			isDataEmpty() {
				return this.tableData.length === 0
			}
		},
		onLoad() {
			this.onRefresh()
		},
		onPullDownRefresh() {
			this.onRefresh()
		},
		onReachBottom() {
			this.onBottom()
		},
		methods: {
			handReceive(e) {
				this.$refs.receiva.showEdit(e)
			},
			/**
			 * 	列表
			 * */
			onRefresh() {
				this.tableData = []
				this.queryForm.pageNo = 1
				this.fetchData(true)
			},
			onBottom() {
				if (this.status == 'nomore') return
				this.fetchData()
			},
			async fetchData(isRefresh = false) {
				try {
					if (this.status === 'loading' && !isRefresh) return
					const params = this.$u.deepClone(this.queryForm)
					this.status = 'loading'
					const {
						data
					} = await doBoxList(params)

					if (params.pageNo === 1) {
						this.tableData = data
					} else {
						this.tableData = [...this.tableData, ...data]
					}
					this.status = params.pageSize === data.length ? 'loadmore' : 'nomore'
					this.queryForm.pageNo++
					if (isRefresh) {
						uni.stopPullDownRefresh();
					}
				} catch (e) {
					//TODO handle the exception
					console.log(e)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pack {
		.list {
			padding: 24rpx;

			.item {
				background-color: #FFFFFF;
				border-radius: 20rpx;
				box-sizing: border-box;

				&:not(:first-child) {
					margin-top: 18rpx;
				}

				&-left {
					flex: 1;
					border-right: 1rpx dotted #C2C2C2;
					padding: 30rpx;

					.name {
						font-size: 32rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #333333;
					}

					.exit-time {
						margin-top: 8rpx;
						font-size: 26rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
					}
				}

				.btn {
					padding: 0 30rpx;

					button {
						height: 62rpx;
						background: linear-gradient(180deg, #A492FD 0%, #6348F4 100%);
						border-radius: 34rpx;
						font-size: 30rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						display: flex;
						align-items: center;
						justify-content: center;

						&::after {
							border: none;
						}
					}
				}
			}
		}
	}
</style>